package web.service.Impl;

import web.bean.Tousu;
import web.bean.Zichan;
import web.dao.Impl.TouSuDaoImpl;
import web.dao.TouSuDao;
import web.service.TouSuService;
import web.vo.PageVo;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class TouSuServiceImpl implements TouSuService {
    TouSuDao touSuDao=new TouSuDaoImpl();
    @Override
    public PageVo<Tousu> findByInfo(Integer pageSize, Integer pageNo, String startTime, String endTime, String name) {
        Integer params1=(pageNo-1)*pageSize;
        Integer params2=pageSize;
        List<Tousu> info = touSuDao.findInfo(params1, params2, startTime, endTime, name);
        int count = touSuDao.count(startTime, endTime, name);
        PageVo<Tousu> pageVo=new PageVo<>();
        pageVo.setPageNo(pageNo);
        pageVo.setPageSize(pageSize);
        pageVo.setPageCount(count/pageSize+(count%pageSize==0?0:1));
        pageVo.setCount(count);
        pageVo.setData(info);
        return pageVo;
    }

    @Override
    public int add(Tousu tousu) {
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(date);
        tousu.setAddtime(format);
        return touSuDao.add(tousu);
    }

    @Override
    public int del(Integer[] delIds) {
        return touSuDao.del(delIds);
    }

    @Override
    public int editInfo(Tousu tousu) {
        return touSuDao.editInfo(tousu);
    }

    @Override
    public Tousu findTouSu(Integer id) {
        return touSuDao.findTouSu(id);
    }
}
